package com.cwits.wifi.util;

import android.graphics.Bitmap;
import android.view.View;

import com.cwits.wifi.data.beans.FileInfo;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.List;

/**
 * Created by Administrator on 2016-03-03.
 */
public class SavePictureUtil {
    /**保存截图的方法*/
    public static boolean saveScreen(View view,String root_path){

        File rootDir = new File(root_path + "/");
        if(!rootDir.exists()){
            rootDir.mkdirs();
        }
        view.setDrawingCacheEnabled(true);
        view.buildDrawingCache();
        Bitmap bitmap = view.getDrawingCache();
//        Canvas canvas = new Canvas();
//        canvas.drawBitmap(bitmap,bitmap.getWidth(),bitmap.getHeight(),null);
        try {
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(new File(rootDir,"JPG_"+TimeFormater.dateLongFormatString(System.currentTimeMillis(),TimeFormater.format1)+".JPG")));
            return true;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return false;
        }finally{
            view.setDrawingCacheEnabled(false);
            bitmap = null;
        }
    }
    public  int saveNum(String root_path){
        List<FileInfo> allDataInfoList = AppUtil.getLocalFileInfo(root_path);
        int num = 0;
        for (int i = 0; i <allDataInfoList.size() ; i++) {
           if(num< Integer.valueOf(allDataInfoList.get(i).getTitle().substring(3, 6))){
               num = Integer.valueOf(allDataInfoList.get(i).getTitle().substring(3, 6));
           }
        }
        return num;
    }
}
